package cn.dengta.webapp.user.vo;

import java.util.Map;

import cn.dengta.common.model.State;
import cn.dengta.common.model.Status;
import cn.dengta.webapp.base.vo.AbstractVO;
import cn.dengta.webapp.user.cache.UserSummary;
import cn.dengta.webapp.user.entity.Relation;
import cn.dengta.webapp.user.entity.User;
import lombok.Getter;
import lombok.Setter;
import me.codeplayer.util.StringUtil;

@Getter
@Setter
public class FollowVO extends AbstractVO<Relation> {

	/** 业务状态 */
	public Integer status;
	/** 操作用户ID */
	public Map<String, Object> user;
	/** 操作用户ID */
	public Map<String, Object> followed;
	/** 业务状态: 0=未关注，1=关注，2=被关注，3=互相关注 */
	public Integer tabStatus;
	/** 用户info 信息 */
	public Map<String, Object> info;
	/** 显示状态 */
	public State state;

	public static FollowVO from(Relation source) {
		return copy(source, FollowVO::new);
	}

	public static FollowVO fromFront(Relation source, UserSummary followed, String alias) {
		FollowVO vo = copy(source, FollowVO::new, "status", "state");
		if (vo != null) {
			vo.followed = User.asEmbedWithAge(followed, alias);
		}
		return vo;
	}

	public static Integer tabStatus(Relation source, boolean fromOrTo) {
		if (source != null && source.getStatus() >= 0 && source.getToStatus() >= 0) {
			Integer status = source.getStatus();
			Integer toStatus = source.getToStatus();
			if (status == 0 && toStatus == 0) {
				return 0;
			} else if (status > 0 && toStatus == 0) {
				return fromOrTo ? 1 : 2;
			} else if (toStatus > 0 && status == 0) {
				return fromOrTo ? 2 : 1;
			} else {
				return 3;
			}
		}
		return null;
	}

	public void putAvatarFrame(String frame) {
		if (this.user != null && StringUtil.notEmpty(frame)) {
			this.user.put("avatarFrame", frame);
		}
	}

	public void putLevel(Integer level) {
		if (this.followed != null && level != null) {
			this.followed.put("level", level);
		}
	}

	public String getStatus_() {
		if (status == null) {
			return null;
		}
		return Status.asResult(status) ? "已关注" : "取消关注";
	}

	public Integer getState() {
		return super.stateOutput(state);
	}

	public String getState_() {
		return super.getState_(state);
	}



}
